<?php

class Model_Item_meta {

    protected $meta_id;
    protected $item_id;
    protected $field_id;
    protected $value;

    public function __construct(array $options = null) {
        if (is_array($options)) {
            $this->setOptions($options);
        }
    }

    public function __set($name, $value) {
        $method = 'set' . ucfirst($name);
        if (('mapper' == $name) || !method_exists($this, $method)) {
            throw new Exception('Invalid content property');
        }
        $this->$method($value);
    }

    public function __get($name) {
        $method = 'get' . ucfirst($name);
        if (('mapper' == $name) || !method_exists($this, $method)) {
            throw new Exception('Invalid content property');
        } return $this->$method();
    }

    public function setOptions(array $options) {
        $methods = get_class_methods($this);
        foreach ($options as $key => $value) {
            $method = 'set' . ucfirst($key);
            if (in_array($method, $methods)) {
                $this->$method($value);
            }
        }
    }

    public function setMeta_id($value) {
        $this->meta_id = $value;
    }

    public function getMeta_id() {
        return $this->meta_id;
    }

    public function setItem_id($value) {
        $this->item_id = $value;
    }

    public function getItem_id() {
        return $this->item_id;
    }

    public function setField_id($value) {
        $this->field_id = $value;
    }

    public function getField_id() {
        return $this->field_id;
    }

    public function setValue($value) {
        $this->value = $value;
    }

    public function getValue() {
        return $this->value;
    }

    public function toArray() {
        return get_object_vars($this);
    }

}

